<template>
  <a-modal
    title="编辑配方"
    :visible="show"
    :confirm-loading="loading"
    @ok="handleOk"
    @cancel="handleCancel"
    :maskClosable="false"
    width="30%"
    class="procedure-modal"
  >
    <div class="title">
      <a-form-model
        :label-col="{ span: 6 }"
        :wrapper-col="{ span: 14 }"
        :model="form"
        :rules="formRules"
        ref="form"
      >
        <a-form-model-item label="产品编码">
          <a-input v-model="form.MaterialCode" disabled />
        </a-form-model-item>
        <a-form-model-item label="产品名称">
          <a-input v-model="form.MaterialName" disabled />
        </a-form-model-item>
        <a-form-model-item label="版本号">
          <a-input v-model="form.VersionName" disabled />
        </a-form-model-item>
        <a-form-model-item label="基准量" required prop="ReferenceAmount">
          <a-input v-model="form.ReferenceAmount" />
        </a-form-model-item>
        <a-form-model-item label="备注">
          <a-textarea style="resize: none" v-model="form.InputRemark" />
        </a-form-model-item>
      </a-form-model>
    </div>
  </a-modal>
</template>

<script>
import { updateERecipe } from "@/api/formula/index";
export default {
  props: ["show", "edit", "form", "procedureData"],
  data() {
    return {
      loading: false, //弹窗loading

      formRules: {
        ReferenceAmount: [
          { required: true, message: "请输入基准量", trigger: "blur" },
        ],
      },
    };
  },
  methods: {
    //关闭弹窗
    handleCancel() {
      this.$refs.form.clearValidate();
      this.$emit("update:show", false);
    },

    //确认添加/修改
    handleOk() {
      this.$refs.form.validate(async (valid) => {
        if (valid) {
          this.loading = true;
          try {
            await updateERecipe(this.form);
            this.$message.success("修改成功");
            this.$emit("update:show", false);
            this.$emit("edit");
          } catch (e) {
            this.$message.error(e);
          } finally {
            this.loading = false;
          }
        }
      });
    },
    //表格选择
    handleTableChange() {},
  },

  watch: {},
};
</script>

<style lang="less" scoped></style>
